package com.red.star.wechat.data.mappers;

import com.red.star.wechat.data.core.base.MyMapper;
import com.red.star.wechat.data.entity.ImagePoster;
import com.red.star.wechat.data.entity.Poster;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author xuquanyu
 * @date 2018/8/16.
 * 二维码管理
 */
public interface ImagePosterMapper extends MyMapper<ImagePoster> {

    List<ImagePoster> imagePosterList(@Param("imagePoster") ImagePoster imagePoster,
                                      @Param("flag") int flag);

    void updateStatusById(@Param("id") Integer id);

    @Select(value = "select count(1) from t_image_poster t where t.poster_id = #{posterId}  and t.mall_code = #{mallCode} and t.`status` = 0")
    Integer selectPosterCountByMallCode(@Param("posterId") Integer posterId, @Param("mallCode") String mallCode);

    @Select(value = "select * from t_image_poster t where t.type = #{type}  and (t.mall_code = #{mallCode} or t.mall_code ='') and t.`status` = 0 order by id desc")
    List<ImagePoster> selectPoster(@Param("type") Integer type, @Param("mallCode") String mallCode);

    List<ImagePoster> selectPosterByPosterId(@Param("imagePosterList") List<ImagePoster> imagePosterList, @Param("type") Integer type);

    List<ImagePoster> findImagePosterByImageTemplateId(@Param("imageTemplateId") Integer imageTemplateId);

    List<ImagePoster> findImagePosterByMallCode(@Param("mallCode") String mallCode);

    List<ImagePoster> checkImagePosterIsExist(@Param("imagePosterList") List<Poster> imagePosterList, @Param("type") Integer type);

    List<Integer> selectPosterByTemplateId(@Param("imageTemplateId") Integer imageTemplateId);

    List<ImagePoster> selectPosterByTemplateIdAndType(@Param("imageTemplateId") Integer imageTemplateId);

    List<ImagePoster> selectPosterByActivityIdAndType(@Param("imageActivityId") Integer imageActivityId);

    List<ImagePoster> findPosterNameByMallCode(@Param("mallCode") String mallCode, @Param("type") Integer type);

    ImagePoster findImagePosterIsUnique(@Param("posterId") Integer posterId, @Param("type") Integer type);

    @Select("select * from t_image_poster t where t.poster_id = #{posterId} and t.`status` = 0 and t.type = #{type} limit 1")
    ImagePoster findByPosterIdAType(@Param("posterId") Integer posterId, @Param("type") int type);

    /**
     * 根据模板id查询活动关联的二维码
     *
     * @param imageTemplateId
     * @return
     */
    List<ImagePoster> findByImageTemplateId(@Param("imageTemplateId") Integer imageTemplateId);

    /**
     * 根据裂变活动id查询活动关联的二维码
     *
     * @param imageActivityId
     * @return
     */
    List<ImagePoster> findByImageActivityId(@Param("imageActivityId") Integer imageActivityId);
}
